﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using PowerCreator.LMS.Download.Entity;
using PowerCreator.LMS.Web.Download;
using PowerCreator.LMS.Common.Script;
public partial class sysadmin_DownManager_ManagerDownType : PowerCreator.LMS.Web.Base.WebBasePage
{
    DownType objDownType = new DownType();
    Download objDownload = new Download();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
            string search = GetSearch();
            BinderPager(search);
            BinderPG(search, 1);
        }
    }

    protected override void InitPage()
    {
        lbl_InfoTitle_ManagerDownType.Text = GetLanageValueByKey("lab_ManagerDownType_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_ManagerDownType.Text = GetLanageValueByKey("lab_ManagerDownType_DownloadTypeList", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnAddNew.Text = GetLanageValueByKey("btn_AddNew", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnSearch.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private string GetSearch()
    {
        string search = string.Format("DownTypeName like '%{0}%'", txt_DownTypeName.Text.Trim());
        return search;
    }

    protected void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objDownType.Count(search);
        AspNetPager1.PageSize = LMSPageSize;
    }
    protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            LinkButton lbtn = (LinkButton)e.Item.FindControl("lnkbtn_del");
            lbtn.Attributes.Add("onClick", "javascript:return confirm('确定删除此记录？');");
        }
    }


    private void BinderPG(string search,int pageIndex)
    {
        DataTable dt = objDownType.Query(search, LMSPageSize, pageIndex);
        rptDownType.DataSource = dt;
        rptDownType.DataBind();

        PreAspNetPager(AspNetPager1);
    }  

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderPG(search,1);
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        string url = "AddDownType.aspx";
        Script.RedirectURL(url);
    }
  
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPG(search, AspNetPager1.CurrentPageIndex);
    }
    protected void rptDownType_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Label lbl_msg = (Label)e.Item.FindControl("lbl_msg");

        if (e.CommandName.ToLower() == "leditor")
        {
            //if (IsLicensed("DownloadTypeUpdate"))
            //{
                string url = "AddDownType.aspx?DownTypeID=" + e.CommandArgument.ToString();
                Script.RedirectURL(url);
            //}
            //else
            //{
            //    lbl_msg.Text = GetLanageValueByKey("msg_ManagerNew_checkmsg", PowerCreator.LMS.Language.LanagetItemType.Page);
            //}
        }
        else if (e.CommandName.ToLower() == "ldel")
        {
            //if (IsLicensed("DownloadTypeDel"))
            //{
                DataTable dt_Download= objDownload.Query(" FKDownDownTypeID="+e.CommandArgument.ToString());
                if (dt_Download.Rows.Count != 0)
                {
                    Script.Alert(this, "", GetLanageValueByKey("Msg_ManagerNewType_checkMsg2", PowerCreator.LMS.Language.LanagetItemType.Page));
                    return;
                }
                if (objDownType.Del(int.Parse(e.CommandArgument.ToString())))
                {
                    string search = GetSearch();
                    BinderPager(search);
                    BinderPG(search, AspNetPager1.CurrentPageIndex);
                }
                else
                {
                    lbl_msg.Text = GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page);
                }
            //}
            //else
            //{
            //    lbl_msg.Text = GetLanageValueByKey("msg_ManagerNew_checkmsg", PowerCreator.LMS.Language.LanagetItemType.Page);
            //}
        }

    }
}
